
const { User } = require('../models/user')

const login = async (req, res, next) => {
    try {
        const user = req.user.toJSON()
        delete user.password
        res.status(200).json(user)
    } catch(err) {
        next(err)
    }
}

const register = async (req, res, next) => {
    try {
        let result = await User.create(req.body)
        let user = result.toJSON()
        delete user.password
        res.status(200).json(user)
    } catch(err) {
        next(err)
    }  
}

module.exports = {
    login,
    register
}